﻿namespace HuaWei.EI
{
    using HuaWei.CommClass;
    using HuaWei.Common;
    using HuaWei.DAI;
    using HuaWei.Windows.Forms;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    public class BaseIE
    {
        [CompilerGenerated]
        private string _str;
        [CompilerGenerated]
        private string _str1;
        [CompilerGenerated]
        private string _str2;
        public IDataAccess ida = null;
        public List<TableInfo> list;
        public List<TableInfo> tableInfoList;
        [CompilerGenerated]
        private string YfQclfhSo;

        public BaseIE()
        {
            this.ida = DBHelp.IniIDA();
            this.tableInfoList = SysDtManager.IniJLTableList();
            this.list = SysDtManager.IniXMTableList();
        }

        public string BuildSQLParam(string sql)
        {
            return sql.Replace("#bdid#", this.BDID).Replace("#qcid#", this.QCID);
        }

        public void CopyImportData(DataSet dsUpdate, DataSet dsSource, string tableName, [Optional, DefaultParameterValue("")] string condition)
        {
            DataTable table = null;
            DataTable table2 = null;
            table = dsUpdate.Tables[tableName];
            table2 = dsSource.Tables[tableName];
            if (!condition.Equals(""))
            {
                table2.DefaultView.RowFilter = condition;
            }
            foreach (DataRowView view in table2.DefaultView)
            {
                DataRow row = view.Row;
                table.Rows.Add(row.ItemArray);
            }
        }

        public void CopyImportDataForBGLQD(DataSet dsUpdate, DataSet dsSource, string tableName, [Optional, DefaultParameterValue("")] string condition)
        {
            DataTable table = null;
            DataTable table2 = null;
            table = dsUpdate.Tables[tableName];
            table2 = dsSource.Tables[tableName];
            if (!condition.Equals(""))
            {
                table2.DefaultView.RowFilter = condition;
            }
            foreach (DataRowView view in table2.DefaultView)
            {
                DataRow drAdd = table.NewRow();
                foreach (DataColumn dc in table.Columns)
                {
                    if (table2.Columns.Contains(dc.ColumnName))
                    {
                        drAdd[dc.ColumnName] = view[dc.ColumnName];
                    }
                }
                table.Rows.Add(drAdd);
            }
        }

        public bool DataCheck(string fileId, string sid, SJLX sjlx, string qcid)
        {
            if (SJLX.JG.Equals(sjlx))
            {
                if (!fileId.Equals(GParams._XMID))
                {
                    MsgBox.ShowMsg("请选择本项目的机构数据包后继续此操作!");
                    return false;
                }
            }
            else if ((GParams._BDID != null) && !fileId.Equals(GParams._BDID))
            {
                MsgBox.ShowMsg("请选择本标段的数据包后继续此操作!");
                return false;
            }
            if (sjlx.Equals(SJLX.BGL))
            {
                if (!fileId.Equals(GParams._BDID))
                {
                    MsgBox.ShowMsg("导入的变更令相关数据不是本标段的数据,导入失败!");
                    return false;
                }
            }
            else if (sjlx.Equals(SJLX.JG))
            {
                if (DBHelp.GetDt(string.Format("select id from zzjgxx where xmid='{0}'", fileId), "temp").Rows.Count.Equals(0))
                {
                    MsgBox.ShowMsg("数据无效,导入失败!");
                    return false;
                }
            }
            else if (sjlx.Equals(SJLX.YZSP))
            {
                if (DBHelp.GetDt(string.Format("select id from zzjgxx where id='{0}' or pid='{0}'", sid), "temp").Rows.Count.Equals(0))
                {
                    MsgBox.ShowMsg("数据无效,导入失败!");
                    return false;
                }
            }
            else
            {
                if (SJLX.JL.Equals(sjlx))
                {
                    int num2 = CHelp.ConvertInt(DBHelp.GetDt(string.Format("select max(qcid) as qcid from XMQC where bdid='{0}'", fileId), "XMQC").Rows[0][0], 0);
                    if ((CHelp.ConvertInt(qcid, 0) - 1) > num2)
                    {
                        MsgBox.ShowMsg("系统检测出您还没有导入上一期计量数据，请先导入上一期计量数据!");
                        return false;
                    }
                }
                DataTable dt = DBHelp.GetDt(string.Format("select pid from zzjgxx where id='{0}'", sid), "temp");
                if (dt.Rows.Count.Equals(0))
                {
                    MsgBox.ShowMsg("数据无效,导入失败!");
                    return false;
                }
                if (!GParams.LoginId.Equals(dt.Rows[0][0].ToString()))
                {
                    MsgBox.ShowMsg("接收数据只能接收组织机构中前一个岗位的数据,导入失败!");
                    return false;
                }
            }
            return true;
        }

        public DataTable ExecuteDataSetEx(string exeStr, string tableName)
        {
            string str = this.BuildSQLParam(exeStr);
            return this.ida.ExecuteDataSet(str, (CommandType)1, tableName).Tables[tableName];
        }

        public DataTable ExecuteDataSetEx(DataSet ds, string exeStr, string tableName)
        {
            string str = this.BuildSQLParam(exeStr);
            ds.Merge(this.ida.ExecuteDataSet(str, CommandType.Text, tableName));
            return ds.Tables[tableName];
        }

        public bool ExecuteSql(string exeStr)
        {
            ArrayList sqls = new ArrayList();
            sqls.Add(exeStr);
            return this.ida.ExecuteNonQuery(sqls, CommandType.Text);
        }

        public string GetDelIds(DataTable dt, string tableName)
        {
            return DHelp.GetIds(dt.Select("OperateType=3 and BM='" + tableName + "'"), "RecId");
        }

        public DataTable GetEmpDt(DataSet ds, string tableName)
        {
            string exeStr = "select * from " + tableName + " where 1=2";
            ds.Merge(this.ida.ExecuteDataSet(exeStr, CommandType.Text, tableName));
            return ds.Tables[tableName];
        }

        public void ImportLocalData(DataSet dsSource, DataSet dsUpdate)
        {
            string str = "";
            string str2 = "";
            string tableName = "";
            DataTable dt = null;
            DataTable empDt = null;
            DataTable table3 = null;
            DataTable table4 = null;
            foreach (TableInfo info in this.tableInfoList)
            {
                try
                {
                    IEnumerator enumerator2;
                    DataRow current;
                    str2 = info.TableName;
                    tableName = info.TableName + "2";
                    string sql = string.Format("delete from {0} where bdid='{1}' and qcid={2} and sid='{3}'", new object[] { tableName, this.BDID, this.QCID, this.SID });
                    DBHelp.ExeSql(this.ida, sql);
                    empDt = this.GetEmpDt(dsUpdate, tableName);
                    table4 = dsSource.Tables[tableName];
                    table3 = dsSource.Tables[str2];
                    if (table4 != null)
                    {
                        enumerator2 = table4.Rows.GetEnumerator();
                        {
                            while (enumerator2.MoveNext())
                            {
                                current = (DataRow) enumerator2.Current;
                                DataRow row2 = empDt.Rows.Add(current.ItemArray);
                            }
                        }
                    }
                    if (table3 != null)
                    {
                        enumerator2 = table3.Rows.GetEnumerator();
                        {
                            while (enumerator2.MoveNext())
                            {
                                current = (DataRow) enumerator2.Current;
                                empDt.Rows.Add(current.ItemArray)["SID"] = this.SID;
                            }
                        }
                        sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", str2, this.BDID, this.QCID);
                        dt = this.ExecuteDataSetEx(dsUpdate, sql, str2);
                        str = DHelp.GetIds(dt, "id", "");
                        table3.DefaultView.RowFilter = "id not in (" + str + ")";
                        foreach (DataRowView view2 in table3.DefaultView)
                        {
                            current = view2.Row;
                            if (!info.LockField.Equals(""))
                            {
                                current[info.LockField] = 0;
                            }
                            if (info.TableName.Equals("QDJL_M") || info.TableName.Equals("BGQDJL_M"))
                            {
                                current["SPZT"] = -1;
                            }
                            else if ((info.TableName.Equals("QTJL_SPJE") || info.TableName.Equals("QTJL_CFKLX")) || info.TableName.Equals("QTJL_DYYFK"))
                            {
                                current["SHRQ"] = DBNull.Value;
                                current["SHR"] = "";
                                current["SHYJ"] = "";
                            }
                            dt.Rows.Add(current.ItemArray);
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception(info.TableName + ":" + exception.Message);
                }
            }
        }

        public void ImportLocalData1(DataSet dsSource, DataSet dsUpdate)
        {
            string str = "";
            DataTable empDt = null;
            DataTable table2 = null;
            foreach (TableInfo info in this.tableInfoList)
            {
                try
                {
                    if (info.IsMaster && info.Boolean)
                    {
                        DataSet ds = new DataSet();
                        string exeStr = "select id from " + info.TableName + " where bdid='#bdid#' and qcid='#qcid#'";
                        this.ExecuteDataSetEx(ds, exeStr, info.TableName);
                        str = DHelp.GetIds(ds.Tables[info.TableName], "id", "");
                        table2 = dsSource.Tables[info.TableName];
                        if (table2 != null)
                        {
                            table2.DefaultView.RowFilter = "id not in (" + str + ")";
                            DataView defaultView = table2.DefaultView;
                            empDt = this.GetEmpDt(dsUpdate, info.TableName);
                            foreach (DataRowView view2 in defaultView)
                            {
                                DataRow row = view2.Row;
                                if (!info.LockField.Equals(""))
                                {
                                    row[info.LockField] = 0;
                                }
                                if (info.TableName.Equals("QDJL_M") || info.TableName.Equals("BGQDJL_M"))
                                {
                                    row["SPZT"] = -1;
                                }
                                else if ((info.TableName.Equals("QTJL_SPJE") || info.TableName.Equals("QTJL_CFKLX")) || info.TableName.Equals("QTJL_DYYFK"))
                                {
                                    row["SHRQ"] = DBNull.Value;
                                    row["SHR"] = "";
                                    row["SHYJ"] = "";
                                }
                                empDt.Rows.Add(row.ItemArray);
                            }
                            if (info.HasDetail)
                            {
                                this.method3(dsSource, dsUpdate, info.TableName, str);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception(info.TableName + ":" + exception.Message);
                }
            }
        }

        public void ImportTable(DataSet dsSource, DataSet dsUpdate, string tableName, [Optional, DefaultParameterValue(" where bdid='#bdid#'")] string condition)
        {
            DataTable table = dsSource.Tables[tableName];
            if (table != null)
            {
                string exeStr = this.BuildSQLParam("delete from " + tableName + condition);
                this.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                DataTable empDt = this.GetEmpDt(dsUpdate, tableName);
                if (table != null)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        empDt.Rows.Add(row.ItemArray);
                    }
                }
            }
        }

        public void ImportTableByIds(DataSet dsSource, DataSet dsUpdate, string tableName)
        {
            DataTable dt = dsSource.Tables[tableName];
            string str = "";
            if (dt != null)
            {
                string str2 = DHelp.GetIds(dt, "id", "");
                if (str2 != "")
                {
                    str = " where id in (" + str2 + ")";
                }
                string exeStr = this.BuildSQLParam("delete from " + tableName + str);
                this.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                DataTable empDt = this.GetEmpDt(dsUpdate, tableName);
                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        empDt.Rows.Add(row.ItemArray);
                    }
                }
            }
        }

        public bool method()
        {
            string sql = "select count(id) as id from ZZJGXXEX";
            if (DBHelp.GetDt(sql, "dtTemp").Rows.Count == 0)
            {
                MsgBox.ShowMsg("请导入机构信息后继续此操作！");
                return false;
            }
            return true;
        }

        public void method1(DataSet dsSource, DataSet dsUpdate)
        {
            string tableName = "";
            DataTable empDt = null;
            DataTable dt = null;
            foreach (TableInfo info in this.tableInfoList)
            {
                if (info.Boolean)
                {
                    try
                    {
                        DataRow row;
                        tableName = info.TableName + "2";
                        dt = dsSource.Tables[tableName];
                        string exeStr = this.BuildSQLParam("delete from " + tableName + " where bdid='#bdid#' and qcid='#qcid#'");
                        this.ida.ExecuteNonQuery(exeStr, CommandType.Text);
                        empDt = this.GetEmpDt(dsUpdate, tableName);
                        if (dt != null)
                        {
                            dt.DefaultView.RowFilter = "SID<>'" + this.SID + "'";
                            foreach (DataRowView view2 in dt.DefaultView)
                            {
                                row = view2.Row;
                                empDt.Rows.Add(row.ItemArray);
                            }
                        }
                        dt = dsSource.Tables[info.TableName];
                        string str3 = DHelp.GetIds(dt, "id", "SID ='" + GParams.LoginId + "'");
                        if (!str3.Equals("''"))
                        {
                            dt.DefaultView.RowFilter = "SID not in ('" + str3 + "')";
                        }
                        foreach (DataRowView view2 in dt.DefaultView)
                        {
                            row = view2.Row;
                            DataRow row2 = empDt.Rows.Add(row.ItemArray);
                            row2["SID"] = this.SID;
                            row2.EndEdit();
                        }
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(tableName + ":" + exception.Message);
                    }
                }
            }
        }

        private void method2(DataTable dataTable, string _str3)
        {
            if (!_str3.Equals("''"))
            {
                dataTable.DefaultView.RowFilter = "pid not in (" + _str3 + ")";
            }
        }

        private void method3(DataSet dataSet, DataSet dataSet1, string _str3, string _str4)
        {
            DataTable table;
            DataView defaultView;
            DataTable empDt;
            DataRow row;
            if (_str3.Equals("QDJL_M"))
            {
                table = dataSet.Tables["QDJL_MX"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "QDJL_MX");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
                table = dataSet.Tables["QDJL_JSS"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "QDJL_JSS");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
            }
            else if (_str3.Equals("BGQDJL_M"))
            {
                table = dataSet.Tables["BGQDJL_MX"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "BGQDJL_MX");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
                table = dataSet.Tables["BGQDJL_JSS"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "BGQDJL_JSS");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
            }
            else if (_str3.Equals("QTJL_JGTZ"))
            {
                table = dataSet.Tables["QTJL_JGTZMX"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "QTJL_JGTZMX");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
            }
            else if (_str3.Equals("QTJL_CLYFK"))
            {
                table = dataSet.Tables["QTJL_CLYFKCL"];
                this.method2(table, _str4);
                defaultView = table.DefaultView;
                empDt = this.GetEmpDt(dataSet1, "QTJL_CLYFKCL");
                foreach (DataRowView view2 in defaultView)
                {
                    row = view2.Row;
                    empDt.Rows.Add(row.ItemArray);
                }
                string str = DHelp.GetIds(defaultView.ToTable(), "id", "");
                table = dataSet.Tables["QTJL_CLYFKCLPC"];
                if (!str.Equals("''"))
                {
                    table.DefaultView.RowFilter = "pid in (" + str + ")";
                    defaultView = table.DefaultView;
                    empDt = this.GetEmpDt(dataSet1, "QTJL_CLYFKCLPC");
                    foreach (DataRowView view2 in defaultView)
                    {
                        row = view2.Row;
                        row["TYSB"] = 0;
                        row.EndEdit();
                        empDt.Rows.Add(row.ItemArray);
                    }
                }
            }
        }

        public void method4(int qczt)
        {
            if (GParams.QCInfo.QCID.Equals(this.QCID))
            {
                QCInfo qCInfo = GParams.QCInfo;
                qCInfo.QCZT = qczt;
                GParams.QCInfo = qCInfo;
            }
            string exeStr = string.Format("update xmqc set zt={0} where bdid='{1}' and qcid='{2}'", qczt, this.BDID, this.QCID);
            this.ExecuteSql(exeStr);
            foreach (DataRow row in GParams._QCData.Rows)
            {
                if (row["qcid"].Equals(this.QCID))
                {
                    row["ZT"] = qczt;
                    row.EndEdit();
                }
            }
        }

        public bool method5()
        {
            string format = "select * from xmqc where zt=0 and bdid='{0}' and qcid<{1} order by qcid";
            DataTable dt = DBHelp.GetDt(string.Format(format, this.BDID, this.QCID), "XMQC");
            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                MsgBox.ShowMsg(string.Format("第{0}期未接收业主数据，请接收第{0}期业主的数据后再接收本期数据！", row["qcid"].ToString()));
                return false;
            }
            return true;
        }

        public string BDID
        {
            [CompilerGenerated]
            get
            {
                return this.YfQclfhSo;
            }
            [CompilerGenerated]
            set
            {
                this.YfQclfhSo = value;
            }
        }

        public string BDName
        {
            [CompilerGenerated]
            get
            {
                return this._str2;
            }
            [CompilerGenerated]
            set
            {
                this._str2 = value;
            }
        }

        public string QCID
        {
            [CompilerGenerated]
            get
            {
                return this._str;
            }
            [CompilerGenerated]
            set
            {
                this._str = value;
            }
        }

        public string SID
        {
            [CompilerGenerated]
            get
            {
                return this._str1;
            }
            [CompilerGenerated]
            set
            {
                this._str1 = value;
            }
        }
    }
}

